<template>
  <div class="picture">
    <h2>我是Picture，现在一共有{{persons.length}}个人在看图片</h2>
    <button @click="handleClick">获取一张随机的图片</button>
    <br>
    <img v-for="item in pictures" :key="item.id" :src="item.url">
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name:'Picture',
    computed: {
      ...mapState(['pictures','persons'])
    },
    methods: {
      handleClick(){
        this.$store.dispatch('getPicture')
      }
    },
  }
</script>

<style scoped>
  .picture {
    background-color: skyblue;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 0 10px;
  }
  img {
    height: 100px;
    margin-right: 10px;
    margin-top: 5px;
  }
</style>